//
//  1-01.c
//  LearningOpenGL
//
//  Created by wangrui on 14-7-4.
//  Copyright (c) 2014年 PPS. All rights reserved.
//

#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
#include <stdio.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated" //消除 ‘废弃的api’ 警告，GLUT已全部在Mac上废除，可用glfw替换


void display()
{
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
	
	glBegin(GL_POLYGON);
	glVertex3f(0.25, 0.25, 0.0);
	glVertex3f(0.75, 0.25, 0.0);
	glVertex3f(0.75, 0.75, 0.0);
	glVertex3f(0.25, 0.75, 0.0);
	glEnd();
	
	glFlush();
}

void initViewingValue()
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

void windowSizeReshape()
{
	printf("window size changed! \n");
}

void keyboardPress(unsigned char key, int x, int y)
{
	printf("keyboardPress! %c,%d,%d\n",key,x,y);
}

void mouseClick(int button, int state, int x, int y)
{
	printf("mouse click! %d,%d,%d,%d\n",button,state,x,y);
}

void mouseDraged(int x,int y)
{
	printf("mouse Draged! %d,%d\n",x,y);
}

int main(int argc, char **argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(300, 300);
	glutCreateWindow("fisrt open gl window");
	
	initViewingValue();
	
	glutDisplayFunc(display);
	
	//event
	glutReshapeFunc(windowSizeReshape);
	glutKeyboardFunc(keyboardPress);
	glutMouseFunc(mouseClick);
	glutMotionFunc(mouseDraged);
	
	glutMainLoop();
	
	return 0;
}

#pragma clang diagnostic pop

